import * as api from "@/api";
import { defineStore } from "pinia";
import { formatDate } from '@/lib/formDate'
export const useSendReq = defineStore("useSendReq", {
    state() {
        return {};
    },
    getters: {

    },
    actions: {
        formatDate(data: string) {
            const YMD = new Date(data)
                .toLocaleString()
                .toString()
                .split(" ")[0]
                .split("/");
            YMD[0] += "年";
            YMD[1] += "月";
            YMD[2] += "日";
            return YMD.join('')
        },
        songDetail: (songs: any): any => {
            const song: any = {}
            song.id = songs[0].id;
            song.name = songs[0].name;
            song.album = songs[0].al.name;
            song.artist = songs[0].ar[0].name;
            song.pic = songs[0].al.picUrl;
            song.picc = songs[0].al.picUrll;
            song.time = formatDate(new Date(songs[0].dt), 'mm:ss')
            return song
        },
        baseInfo: (playlist: any): any => {
            const baseInfo: any = {}
            baseInfo.img = playlist.coverImgUrl || '';
            baseInfo.title = playlist.description;
            baseInfo.name = playlist.name;
            baseInfo.shareCount = playlist.shareCount;
            baseInfo.subscribedCount = playlist.subscribedCount;
            baseInfo.playCount = playlist.playCount;
            baseInfo.trackCount = playlist.trackCount;
            baseInfo.tags = playlist.tags;
            baseInfo.createTime = new Date(playlist.createTime).toLocaleString().split(" ")[0].split('/').join('-')
            baseInfo.creatorAvatar = playlist.creator.avatarUrl;
            baseInfo.creatorName = playlist.creator.nickname;
            return baseInfo
        },
        // individuality 开始
        // 推荐
        getRecommendAndBanner() {
            return Promise.all([api.reqRecommend(), api.reqBanner()]);
        },
        // 独家放送
        getPrivate() {
            return api.reqPrivate();
        },
        // 最新
        getNewMusic() {
            return api.reqNewMusic();
        },

        // allmusiclist开始
        getAllMusicList(params: { offset: number }) {
            return api.reqAllmusiclist(params)
        },
        // 热门标签
        getSelectHot() {
            return api.reqSelectHot()
        },
        // 全部标签
        getCatList() {
            return api.reqCatList()
        },
        // ranklist 排行版开始
        getTopList() {
            return api.reqTopList()
        },
        //  歌单详情
        getMusicDetail(id: number) {
            return api.reqMusicDetail(id)
        },
        // 
        getSongsDetail(ids: any) {
            return api.reqSongsDetail(ids)
        },
        // 歌手开始
        getReqArtist(params: sendParams) {
            return api.reqArtist(params)
        },
        // mv
        getMvFirst(params: sendParams) {
            return api.reqMvFirst(params)
        },
        getRecommendMv(params: sendParams) {
            return api.reqRecommendMv(params)
        },
        getMvDetail(id: SN) {
            return api.reqMvDetail(id)
        },
        // mv 评论 mv 推荐
        getMvCommendAndSimi(params: sendParams, mvid: SN) {
            return Promise.all([api.reqMvComment(params), api.reqMvSimi(mvid)])
        },
        //  最新音乐
        getTopSong(type: string | number) {
            return api.reqTopSong(type)
        },
        // 最新音乐详情 reqTopSongDetail
        getTopSongDetail(ids: string | number) {
            return api.reqTopSongDetail(ids)
        },
        // 歌单详情信息
        getPlayDetail(id: string | number) {
            return api.reqPlayDetail(id)
        },
        // 播放音乐
        getPlayMusic(id: string | number) {
            return api.reqPlayMusic(id)
        },
        // 歌词
        getLyric(id: number | string) {
            return api.reqLyric(id)
        },
        // 歌曲评论
        getComment(params: sendParams) {
            return api.reqComment(params)
        }
    },
});
